package com.sicheng.lc.周赛.分类.思维;

import java.util.Arrays;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/15 11:20
 */
public class 不含特殊楼层的最大连续楼层数 {
    //https://leetcode.cn/problems/maximum-consecutive-floors-without-special-floors/
    public int maxConsecutive(int bottom, int top, int[] special) {
        Arrays.sort(special);
        int last = bottom;
        int max = -1;
        for (int x : special) {
            if (x >= bottom && x <= top) {
                max = Math.max(x - last, max);
                last = x + 1;
            } else if (x > top) {
                break;
            }
        }
        if (last < top)
            return Math.max(max, top - last + 1);
        return max;
    }

}
